/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SystemSettingsManager.java
 *
 * Created on Jan 8, 2010, 5:20:49 PM
 */

package pcs.gui;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jfree.beans.JPieChart;
import org.jfree.beans.LegendPosition;
import org.jfree.data.general.DefaultPieDataset;
import pcs.SystemSettings;

/**
 *
 * @author ahmet
 */
public class SystemSettingsManager extends javax.swing.JDialog {

    /** Creates new form SystemSettingsManager */
    private pcs.SystemSettings systemSettings;
    private final JFrame parent;

    public SystemSettingsManager(final JFrame parent, boolean modal) {
        super(parent, modal);
        this.parent = parent;
        ((MainFrame)parent).setSettingsButtonEnabled(false);

        initComponents();
        setLocationRelativeTo(null);

        if (!warnDeteriorationWithPopup.isSelected() && !warnDeteriorationWithSound.isSelected()) {
            warnDeteriorationWithRestriction.setEnabled(false);
            warnDeteriorationWithRestriction.setSelected(false);
            warnDeteriorationTimeUntilRestriction.setEnabled(false);
            warnDeteriorationWithRestrictionAdditionalText.setEnabled(false);
        }

        if (!warnForBreakWithPopup.isSelected() && !warnForBreakWithSound.isSelected()) {
            warnForBreakWithRestriction.setEnabled(false);
            warnForBreakWithRestriction.setSelected(false);
            warnForBreakTimeUntilRestriction.setEnabled(false);
            warnForBreakWithRestrictionAdditionalText.setEnabled(false);
        }


        warnDeteriorationWithPopup.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent ce) {
                if (warnDeteriorationWithPopup.isSelected()) {
                    warnDeteriorationWithRestriction.setEnabled(true);
                    warnDeteriorationTimeUntilRestriction.setEnabled(true);
                    warnDeteriorationWithRestrictionAdditionalText.setEnabled(true);
                } else {
                    if (!warnDeteriorationWithSound.isSelected()) {
                        warnDeteriorationWithRestriction.setEnabled(false);
                        warnDeteriorationWithRestriction.setSelected(false);
                        warnDeteriorationTimeUntilRestriction.setEnabled(false);
                        warnDeteriorationWithRestrictionAdditionalText.setEnabled(false);
                    }
                }
            }
        });

        warnDeteriorationWithSound.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent ce) {
                warnDeteriorationWithRestrictionAdditionalText.setForeground(warnDeteriorationWithRestriction.getForeground());
                if (warnDeteriorationWithSound.isSelected()) {
                    warnDeteriorationWithRestriction.setEnabled(true);
                    warnDeteriorationTimeUntilRestriction.setEnabled(true);
                    warnDeteriorationWithRestrictionAdditionalText.setEnabled(true);
                } else {
                    if (!warnDeteriorationWithPopup.isSelected()) {
                        warnDeteriorationWithRestriction.setEnabled(false);
                        warnDeteriorationWithRestriction.setSelected(false);
                        warnDeteriorationTimeUntilRestriction.setEnabled(false);
                        warnDeteriorationWithRestrictionAdditionalText.setEnabled(false);
                    }
                }
            }
        });

        warnForBreakWithPopup.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent ce) {
                if (warnForBreakWithPopup.isSelected()) {
                    warnForBreakWithRestriction.setEnabled(true);
                    warnForBreakTimeUntilRestriction.setEnabled(true);
                    warnForBreakWithRestrictionAdditionalText.setEnabled(true);
                } else {
                    if (!warnForBreakWithSound.isSelected()) {
                        warnForBreakWithRestriction.setEnabled(false);
                        warnForBreakWithRestriction.setSelected(false);
                        warnForBreakTimeUntilRestriction.setEnabled(false);
                        warnForBreakWithRestrictionAdditionalText.setEnabled(false);
                    }
                }
            }
        });

        warnForBreakWithSound.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent ce) {
                warnForBreakWithRestrictionAdditionalText.setForeground(warnForBreakWithRestriction.getForeground());
                if (warnForBreakWithSound.isSelected()) {
                    warnForBreakWithRestriction.setEnabled(true);
                    warnForBreakTimeUntilRestriction.setEnabled(true);
                    warnForBreakWithRestrictionAdditionalText.setEnabled(true);
                } else {
                    if (!warnForBreakWithPopup.isSelected()) {
                        warnForBreakWithRestriction.setEnabled(false);
                        warnForBreakWithRestriction.setSelected(false);
                        warnForBreakTimeUntilRestriction.setEnabled(false);
                        warnForBreakWithRestrictionAdditionalText.setEnabled(false);
                    }
                }
            }
        });

        warnForBreakTimeUntilWarning.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent ce) {
                drawWorkBreakChart();
            }
        });

        warnForWorkTimeUntilWarning.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent ce) {
                drawWorkBreakChart();
            }
        });

        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent we) {
                super.windowClosing(we);
                ((MainFrame)parent).setSettingsButtonEnabled(true);
                setVisible(false);
            }
        } );

        setResizable(false);

        systemSettings = new SystemSettings();
        showSettings();
        drawWorkBreakChart();
    }

    private JPieChart pie;
    private void drawWorkBreakChart() {
        DefaultPieDataset dataset = new DefaultPieDataset();
        double tuw = (Double)warnForBreakTimeUntilWarning.getValue();
        double wtuw = (Double)warnForWorkTimeUntilWarning.getValue();
        dataset.setValue("Working Time", tuw);
        dataset.setValue("Break Time", wtuw);

        if(pie == null) {
            pie = new JPieChart();

            JPanel jp = new JPanel();
            jp.setSize(100, 30);
            jp.setBackground(pie.getBackground());
            pie.setLayout(new BorderLayout());
            pie.add(jp, BorderLayout.SOUTH);
            pie.setLegendPosition(LegendPosition.NONE);

            pie.setTitle("Work/Break Cycle");


            workbreakchart.setLayout(new BorderLayout());
            workbreakchart.add(pie);
        }
        String totalString = Double.toString(tuw+wtuw);
        if (totalString.indexOf(".") != -1) {
            int i = totalString.indexOf(".");
            totalString = totalString.substring(0, i+2);
            if (totalString.substring(i+1, i+2).equals("0")) {
                totalString = totalString.substring(0, i);
            }
        }

       pie.setSubtitle("Total: "+totalString+ " minutes");
       pie.setDataset(dataset);
    }

    private void showSettings() {
        warnDeteriorationWithPopup.setSelected(systemSettings.isWarnDeteriorationWithPopup());
        warnDeteriorationWithSound.setSelected(systemSettings.isWarnDeteriorationWithSound());
        warnDeteriorationWithRestriction.setSelected(systemSettings.isWarnDeteriorationWithRestriction());
        warnDeteriorationTimeUntilRestriction.setValue(systemSettings.getWarnDeteriorationTimeUntilRestriction());

        warnForBreakTimeUntilWarning.setValue(systemSettings.getWarnForBreakTimeUntilWarning()); //In minutes
        warnForBreakWithPopup.setSelected(systemSettings.isWarnForBreakWithPopup());
        warnForBreakWithSound.setSelected(systemSettings.isWarnForBreakWithSound());
        warnForBreakWithRestriction.setSelected(systemSettings.isWarnForBreakWithRestriction());
        warnForBreakTimeUntilRestriction.setValue(systemSettings.getWarnForBreakTimeUntilRestriction());

        warnForWorkTimeUntilWarning.setValue(systemSettings.getWarnForWorkTimeUntilWarning()); //In minutes
        warnForWorkWithPopup.setSelected(systemSettings.isWarnForWorkWithPopup());
        warnForWorkWithSound.setSelected(systemSettings.isWarnForWorkWithSound());
    }

    private void saveSettings() {
        systemSettings.setWarnDeteriorationWithPopup(warnDeteriorationWithPopup.isSelected());
        systemSettings.setWarnDeteriorationWithSound(warnDeteriorationWithSound.isSelected());
        systemSettings.setWarnDeteriorationWithRestriction(warnDeteriorationWithRestriction.isSelected());
        double tur = (Double)warnDeteriorationTimeUntilRestriction.getValue();
        systemSettings.setWarnDeteriorationTimeUntilRestriction(tur);

        double tuw = (Double)warnForBreakTimeUntilWarning.getValue();
        systemSettings.setWarnForBreakTimeUntilWarning(tuw);
        systemSettings.setWarnForBreakWithPopup(warnForBreakWithPopup.isSelected());
        systemSettings.setWarnForBreakWithSound(warnForBreakWithSound.isSelected());
        systemSettings.setWarnForBreakWithRestriction(warnForBreakWithRestriction.isSelected());
        double btur = (Double)warnForBreakTimeUntilRestriction.getValue();
        systemSettings.setWarnForBreakTimeUntilRestriction(btur);

        double wtuw = (Double)warnForWorkTimeUntilWarning.getValue();
        systemSettings.setWarnForWorkTimeUntilWarning(wtuw);
        systemSettings.setWarnForWorkWithPopup(warnForWorkWithPopup.isSelected());
        systemSettings.setWarnForWorkWithSound(warnForWorkWithSound.isSelected());

        systemSettings.save();
    }

    private void importSettings() {
       JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileNameExtensionFilter("XML Files", "xml"));
        int returnVal = chooser.showOpenDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
           File file = chooser.getSelectedFile();
           systemSettings.importFrom(file.getAbsolutePath());
           showSettings();
        }
    }

    private void exportSettings() {
       JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileNameExtensionFilter("XML Files", "xml"));
        int returnVal = chooser.showSaveDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
           File file = chooser.getSelectedFile();
           systemSettings.exportTo(file.getAbsolutePath());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        exportButton = new javax.swing.JButton();
        importButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();
        helpButton = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        warnDeteriorationWithPopup = new javax.swing.JCheckBox();
        warnDeteriorationWithSound = new javax.swing.JCheckBox();
        warnDeteriorationWithRestriction = new javax.swing.JCheckBox();
        jLabel7 = new javax.swing.JLabel();
        warnDeteriorationWithRestrictionAdditionalText = new javax.swing.JLabel();
        warnDeteriorationTimeUntilRestriction = new javax.swing.JSpinner();
        jPanel3 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        warnForBreakWithPopup = new javax.swing.JCheckBox();
        warnForBreakWithSound = new javax.swing.JCheckBox();
        warnForBreakWithRestriction = new javax.swing.JCheckBox();
        warnForWorkWithPopup = new javax.swing.JCheckBox();
        warnForWorkWithSound = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        warnForBreakTimeUntilWarning = new javax.swing.JSpinner();
        warnForWorkTimeUntilWarning = new javax.swing.JSpinner();
        warnForBreakWithRestrictionAdditionalText = new javax.swing.JLabel();
        warnForBreakTimeUntilRestriction = new javax.swing.JSpinner();
        workbreakchart = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Settings Manager");

        exportButton.setText("Export");
        exportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportButtonActionPerformed(evt);
            }
        });

        importButton.setText("Import");
        importButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        okButton.setText("Ok");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        helpButton.setText("Help");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(exportButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(importButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, Short.MAX_VALUE)
                .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(helpButton))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(exportButton)
                .addComponent(importButton)
                .addComponent(helpButton)
                .addComponent(cancelButton)
                .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Other"));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 514, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 141, Short.MAX_VALUE)
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Warnings"));

        warnDeteriorationWithPopup.setText("with a warning message in a pop-up window");

        warnDeteriorationWithSound.setText("with sound");

        warnDeteriorationWithRestriction.setText("Restrict computer usage, ");

        jLabel7.setText("Warn me if my posture deteriorates");

        warnDeteriorationWithRestrictionAdditionalText.setText("seconds after the warning");

        warnDeteriorationTimeUntilRestriction.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(20.0d), Double.valueOf(10.0d), null, Double.valueOf(1.0d)));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(warnDeteriorationWithSound)
                            .addComponent(warnDeteriorationWithPopup)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(warnDeteriorationWithRestriction)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(warnDeteriorationTimeUntilRestriction, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(warnDeteriorationWithRestrictionAdditionalText))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel7)))
                .addContainerGap(137, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(warnDeteriorationWithPopup)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(warnDeteriorationWithSound)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(warnDeteriorationWithRestriction)
                    .addComponent(warnDeteriorationWithRestrictionAdditionalText)
                    .addComponent(warnDeteriorationTimeUntilRestriction, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(85, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(10, 10, 10)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Posture Correction", jPanel2);

        warnForBreakWithPopup.setText("with a warning message in a pop-up window");

        warnForBreakWithSound.setText("with sound");

        warnForBreakWithRestriction.setText("Restrict computer usage,");

        warnForWorkWithPopup.setText("with a warning message in a pop-up window");

        warnForWorkWithSound.setText("with sound");

        jLabel3.setText("minutes");

        jLabel4.setText("minutes");

        jLabel5.setText("Warn me to take breaks after working");

        jLabel6.setText("Warn me to go back to work if my break exceeds");

        warnForBreakTimeUntilWarning.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(0.1d), Double.valueOf(0.1d), null, Double.valueOf(1.0d)));

        warnForWorkTimeUntilWarning.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(0.1d), Double.valueOf(0.1d), null, Double.valueOf(1.0d)));

        warnForBreakWithRestrictionAdditionalText.setText("seconds after the warning");

        warnForBreakTimeUntilRestriction.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(10.0d), Double.valueOf(10.0d), null, Double.valueOf(1.0d)));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(warnForBreakTimeUntilWarning, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(warnForBreakWithSound)
                            .addComponent(warnForBreakWithPopup)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(warnForBreakWithRestriction)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(warnForBreakTimeUntilRestriction, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(warnForBreakWithRestrictionAdditionalText))))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(warnForWorkTimeUntilWarning, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(warnForWorkWithSound)
                            .addComponent(warnForWorkWithPopup))))
                .addContainerGap(151, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(warnForBreakTimeUntilWarning, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(warnForBreakWithPopup)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(warnForBreakWithSound)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(warnForBreakWithRestriction)
                    .addComponent(warnForBreakWithRestrictionAdditionalText)
                    .addComponent(warnForBreakTimeUntilRestriction, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(warnForWorkTimeUntilWarning, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(warnForWorkWithPopup)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(warnForWorkWithSound)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout workbreakchartLayout = new javax.swing.GroupLayout(workbreakchart);
        workbreakchart.setLayout(workbreakchartLayout);
        workbreakchartLayout.setHorizontalGroup(
            workbreakchartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 526, Short.MAX_VALUE)
        );
        workbreakchartLayout.setVerticalGroup(
            workbreakchartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 140, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(workbreakchart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(workbreakchart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jTabbedPane1.addTab("Breaks", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed
        // TODO add your handling code here:
        exportSettings();
    }//GEN-LAST:event_exportButtonActionPerformed

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        // TODO add your handling code here:
        saveSettings();
        ((MainFrame)parent).setSettingsButtonEnabled(true);
        setVisible(false);
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // TODO add your handling code here:
        ((MainFrame)parent).setSettingsButtonEnabled(true);
        setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed
        // TODO add your handling code here:
        importSettings();
    }//GEN-LAST:event_importButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SystemSettingsManager dialog = new SystemSettingsManager(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton exportButton;
    private javax.swing.JButton helpButton;
    private javax.swing.JButton importButton;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton okButton;
    private javax.swing.JSpinner warnDeteriorationTimeUntilRestriction;
    private javax.swing.JCheckBox warnDeteriorationWithPopup;
    private javax.swing.JCheckBox warnDeteriorationWithRestriction;
    private javax.swing.JLabel warnDeteriorationWithRestrictionAdditionalText;
    private javax.swing.JCheckBox warnDeteriorationWithSound;
    private javax.swing.JSpinner warnForBreakTimeUntilRestriction;
    private javax.swing.JSpinner warnForBreakTimeUntilWarning;
    private javax.swing.JCheckBox warnForBreakWithPopup;
    private javax.swing.JCheckBox warnForBreakWithRestriction;
    private javax.swing.JLabel warnForBreakWithRestrictionAdditionalText;
    private javax.swing.JCheckBox warnForBreakWithSound;
    private javax.swing.JSpinner warnForWorkTimeUntilWarning;
    private javax.swing.JCheckBox warnForWorkWithPopup;
    private javax.swing.JCheckBox warnForWorkWithSound;
    private javax.swing.JPanel workbreakchart;
    // End of variables declaration//GEN-END:variables

}
